package com.hm.ibsm.window;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

import com.hm.ibsm.su.GlobalContent;
import com.hm.ibsm.su.R;
import com.hm.ibsm.window.main.BottomPanel;
import com.hm.ibsm.window.main.ContentPanel;
import com.hm.ibsm.window.main.LeftMenuPanel;

/**
 * @author shishun.wang
 * @date 2017年2月18日 下午6:05:02
 * @version 1.0
 * @describe
 */
public class MainWindow extends JFrame {

	private static final long serialVersionUID = 8842159157282083828L;

	private MainWindow self = this;

	private ContentPanel contentPanel = new ContentPanel(self);

	private LeftMenuPanel leftMenuPanel = new LeftMenuPanel(self, contentPanel);

	private BottomPanel bottomPanel = new BottomPanel();

	public MainWindow() {
		this.setTitle(R.Configuration.SYSTEM_TITLE);
		GlobalContent.getInstance().loadSystemLogo(this);
		this.setJMenuBar(createMenuBar());
		getContentPane().setLayout(new BorderLayout());

		{// left
			leftMenuPanel.setPreferredSize(new Dimension(280, 50));
			getContentPane().add(leftMenuPanel, BorderLayout.WEST);
		}

		{// bottom
			bottomPanel.setPreferredSize(new Dimension(280, 50));
			getContentPane().add(bottomPanel, BorderLayout.SOUTH);
		}

		{// content
			getContentPane().add(contentPanel, BorderLayout.CENTER);
		}

		this.setVisible(true);
		this.setResizable(true);
		this.setExtendedState(Frame.MAXIMIZED_BOTH);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	private JMenuBar createMenuBar() {
		JMenuBar jMenuBar = new JMenuBar();

		{
			JMenu menu = new JMenu("文件(F)");
			{
				JMenuItem exit = new JMenuItem("退出");
				exit.addActionListener(new ActionListener() {

					public void actionPerformed(ActionEvent e) {
						if (JOptionPane.showConfirmDialog(null, "是否退出系统?", "退出提示", 0) == 0) {
							System.exit(0);
						}
					}
				});
				menu.add(exit);
			}
			jMenuBar.add(menu);
		}

		{
			JMenu menu = new JMenu("编辑(E)");
			menu.setEnabled(false);
			jMenuBar.add(menu);
		}
		{
			JMenu menu = new JMenu("项目(P)");
			menu.setEnabled(false);
			jMenuBar.add(menu);
		}
		
		{
			JMenu menu = new JMenu("运行(R)");
			menu.setEnabled(false);
			jMenuBar.add(menu);
		}
		
		{
			JMenu menu = new JMenu("窗口(W)");
			menu.setEnabled(false);
			jMenuBar.add(menu);
		}

		{
			JMenu menu = new JMenu("选项(S)");

			{
				JMenuItem idCardInfo = new JMenuItem("高级");
				menu.add(idCardInfo);
			}

			{
				JMenuItem paramsSetting = new JMenuItem("参数设置");
				menu.add(paramsSetting);
			}

			jMenuBar.add(menu);
		}

		{// 帮助
			JMenu menu = new JMenu("帮助(H)");
			{
				JMenuItem explan = new JMenuItem("使用说明");
				menu.add(explan);
			}
			{// 关于
				JMenuItem about = new JMenuItem("关于本软件");
				menu.add(about);
			}
			jMenuBar.add(menu);
		}

		return jMenuBar;
	}
}
